/*
 * @(#)SysconfigModify.java   1.0  2021年12月24日
 * 
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.dts.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swift.core.auth.Login;
import com.swift.core.filter.annotation.NoSqlVal;
import com.swift.core.model.ServiceRequest;
import com.swift.core.model.data.DataModel;
import com.swift.core.service.SynInterface;
import com.swift.dts.loadconfig.FileSysConfig;
import com.swift.dts.loadconfig.model.SysConfig;
import com.swift.dts.util.MailUtil.MainSendUser;
import com.swift.util.type.JsonUtil;
import com.swift.util.type.TypeUtil;

/**
 * 添加说明 
 * @author zhengjiajin
 * @version 1.0 2021年12月24日
 */
@Service("sysconfigModify")
@Login
@NoSqlVal
public class SysconfigModify implements SynInterface {

    @Autowired
    private FileSysConfig fileSysConfig;

    /** 
     * @see com.swift.core.service.SynInterface#doService(com.swift.core.model.ServiceRequest)
     */
    @Override
    public DataModel doService(ServiceRequest req) {
        Boolean startConfig = req.getData().getBoolean("startConfig");
        Boolean allowDrop = req.getData().getBoolean("allowDrop");
        Boolean allowTruncate = req.getData().getBoolean("allowTruncate");
        String mainSendUserJson = req.getData().getString("mainSendUser");
        SysConfig sysConfig = fileSysConfig.read();
        if(startConfig!=null)sysConfig.setStartConfig(startConfig);
        if(allowDrop!=null)sysConfig.setAllowDrop(allowDrop);
        if(allowTruncate!=null)sysConfig.setAllowTruncate(allowTruncate);
        if(TypeUtil.isNotNull(mainSendUserJson))sysConfig.setMainSendUser(JsonUtil.toObj(mainSendUserJson, MainSendUser.class));
        fileSysConfig.save(sysConfig);
        return null;
    }
}
